import java.util.*;

/**
 * @author LKQ
 * @date 2022/5/3 14:55
 * @description 前缀和
 */
public class Solution {
    public static void main(String[] args) {

    }

    public int[] getSumAbsoluteDifferences(int[] nums) {
        int n = nums.length;
        long[] preSum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            preSum[i + 1] = preSum[i] + nums[i];
        }
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            ans[i] = (int) ((i + 1) * nums[i] - preSum[i + 1] - (n - i - 1) * nums[i] + preSum[n] - preSum[i + 1]);
        }
        return ans;
    }
}
